﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Security.Claims;
using Wuther.Infrastructure.Organizations;
using Microsoft.AspNetCore.Authorization;
using Wuther.Infrastructure.Permissions;

namespace Wuther.Infrastructure.Controllers
{
    /// <summary>
    /// 部门信息Api
    /// </summary>
    [RemoteService]
    [Area("Infrastructure")]
    [Route($"api/{InfrastructureRemoteServiceConsts.ModuleName}/organization")]
    public class OrganizationController : InfrastructureController, IOrganizationAppService
    {
        private readonly IOrganizationAppService _service;

        public OrganizationController(IOrganizationAppService service)
        {
            _service = service;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="input">参数</param>
        /// <returns></returns>
        [HttpPost]
        //[Authorize(InfrastructurePermissions.Organization.Create)]
        public Task<OrganizationDto> CreateAsync(CreateOrUpdateOrganizationDto input)
        {
            return  _service.CreateAsync(input);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        [HttpDelete]
        [Route("{id}")]
        [Authorize(InfrastructurePermissions.Organization.Delete)]
        public Task DeleteAsync(Guid id)
        {
             return _service.DeleteAsync(id);
        }

        /// <summary>
        /// 获取某条记录
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        [HttpGet]
        [Route("{id}")]
        [Authorize(InfrastructurePermissions.Organization.Default)]
        public Task<OrganizationDto> GetAsync(Guid id)
        {
            return _service.GetAsync(id);
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="input">分页参数</param>
        /// <returns></returns>
        [HttpGet]
        //[Authorize(InfrastructurePermissions.Organization.Default)]
        public Task<PagedResultDto<OrganizationDto>> GetListAsync(GetOrganizationInput input)
        {
            return _service.GetListAsync(input);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <param name="input">参数</param>
        /// <returns></returns>
        [HttpPut]
        [Route("{id}")]
        [Authorize(InfrastructurePermissions.Organization.Update)]
        public Task<OrganizationDto> UpdateAsync(Guid id, CreateOrUpdateOrganizationDto input)
        {
            return _service.UpdateAsync(id,input);
        }

           /// <summary>
        /// 获取列表（不分页）
        /// </summary>
        /// <param name="input">参数</param>
        /// <returns></returns>
        [HttpGet]
        [Route("getAll")]
        [Authorize(InfrastructurePermissions.Organization.Default)]
        public Task<List<OrganizationDto>> GetAllListAsync(GetOrganizationInput input)
        {
            return _service.GetAllListAsync(input);
        }

        [HttpGet]
        [Route("GetTreeList")]
        public Task<List<DeptTreeDto>> GetTreeListAsync(GetOrganizationInput input)
        {
            return _service.GetTreeListAsync(input);
        }
    }
}
